const host = window.location.host
export default {
  // 获取消息订阅
  getSystemInforms(){
    return websocket('ws://'+ host + '/api/ws/message/')
  },

  // 进入房间
  getChatRoom(id=''){
    return websocket('ws://'+ host + '/api/chat/'+ id + '/')
  },
}

const websocket = function(url){
  const socket = new WebSocket(url)
  socket.onopen = () => {
    console.log('开始连接')
  }
  socket.onclose = () => {
    console.log('断开连接')
  }
  socket.onerror = () => {
    console.log('连接失败')
  }
  return socket
}